package name.fowler.refactoring.simplestore;

import java.util.HashMap;
import java.util.Map;

public class PriceCalculatorStore {

	private Map<Category, PriceCalculator> priceCalculators;
	private static PriceCalculatorStore instance = new PriceCalculatorStore(); 
	
	public PriceCalculatorStore() {
		priceCalculators = new HashMap<Category, PriceCalculator>();
	}
	
	public static PriceCalculatorStore getInstance() {
		return instance;
	}
	
	public void add(PriceCalculator priceCalculator) {
		priceCalculators.put(priceCalculator.getCategory(), priceCalculator);
	}
	
	public PriceCalculator find(Category category) 
			throws PriceCalculatorNotFoundException {
		PriceCalculator priceCalculator = priceCalculators.get(category);
		if (priceCalculator == null) {
			throw new PriceCalculatorNotFoundException(category);
		}
		return priceCalculator;
	}
}
